//
//  VisitorView.swift
//  LZGWB
//
//  Created by Leoi ZoengGit on 2016/12/17.
//  Copyright © 2016年 Leoi ZoengGit. All rights reserved.
//

import UIKit

class VisitorView: UIView {
    // 注册按钮
    @IBOutlet weak var registerButton: UIButton!
    // 登录按钮
    @IBOutlet weak var loginButton: UIButton!
    // 文本标签
    @IBOutlet weak var titleLabel: UILabel!
    // 转盘
    @IBOutlet weak var rotationImageView: UIImageView!
    // 图标
    @IBOutlet weak var iconImageView: UIImageView!
    
    func setupVisitorInfo(_ imageName: String? , title: String) {
        
        titleLabel.text = title
        
        guard let name = imageName else {
            startAnimation()
            
            return
        }
        
        rotationImageView.isHidden = true
        
        iconImageView.image = UIImage(named: name)
        
        
    }
    
    // 转盘动画
    fileprivate func startAnimation() {
        // 1.创建动画
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        
        // 2.设置动画属性
        anim.toValue = 2 * M_PI
        anim.duration = 5.0
        anim.repeatCount = MAXFLOAT
        
        anim.isRemovedOnCompletion = false
        
        rotationImageView.layer.add(anim, forKey: nil)
    }
    
    class func visitorView() -> VisitorView {
        return Bundle.main.loadNibNamed("VistorView", owner: nil, options: nil)!.last as! VisitorView
    }
    
}
